using System;
using System.Linq.Expressions;
using LinqSpecs;

namespace PCE.Data.Queries.Tender
{
	internal class OfCustomer : Specification<Domain.Tender>
	{
		private readonly int _customerId;

		private readonly int? _tenderId;

		public OfCustomer(int customerId)
		{
			_customerId = customerId;
		}

		public OfCustomer(int customerId, int tenderId)
			: this(customerId)
		{
			_tenderId = tenderId;
		}

		public override Expression<Func<Domain.Tender, bool>> IsSatisfiedBy()
		{
			return 
			_tenderId.HasValue
			? (Expression<Func<Domain.Tender, bool>>)(t => t.Customer.Id == _customerId && t.Id == _tenderId.Value)
			: t => t.Customer.Id == _customerId
			;
		}
	}
}